<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/website/common/base.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>活动专区_${webname }</title>
    <%@ include file="/website/common/common.jsp" %>
    <link href="${webctx}/css/list.css?v=20170706" rel="stylesheet" type="text/css"/>
    <link href="${webctx }/css/sidebar.css?v=20170616" rel="stylesheet" type="text/css"/>
</head>
<style>
    .array-pic a .sm-mask {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        font-size: 28px;
        color: #fff;
        background-color: #000;
        opacity: .1;
        filter: alpha(opacity=10) \9;
        line-height: 200px;
        text-align: center;
        z-index: 1;
    }

    .array-pic a .sm-mask-center {
        position: absolute;
        top: 43px;
        left: 43px;
        width: 114px;
        height: 114px;
        -webkit-border-radius: 100%;
        -moz-border-radius: 100%;
        border-radius: 100%;
        background-color: #000;
        opacity: .5;
        filter: alpha(opacity=50) \9;
        z-index: 2;
    }

    .array-pic a i {
        font-style: normal;
        position: absolute;
        top: 0;
        left: 0;
        width: 200px;
        height: 200px;
        font-size: 28px;
        color: #fff;
        text-align: center;
        line-height: 200px;
        z-index: 3;
        font-family: "SimSun";
    }

    .array-pic {
        position: relative;
    }

    .cost i {
        font-style: normal;
        text-decoration: line-through;
        font-size: 14px;
        color: #999;
        margin-left: 5px;
    }

    .cost em {
        font-size: 14px;
        color: #ff6767;
        margin-left: 10px;
    }

    .array-pic {
        margin: 17px 17px 0 17px;
    }

    .time-text {
        position: absolute;
        bottom: 5px;
        left: 0;
        right: 0;
        text-align: center;
        line-height: 30px;
        font-size: 12px;
        color: #fff;
        background-color: #000;
        opacity: 0.4;
        filter: "alpha(opacity=40)";
        -ms-filter: "alpha(opacity=40)";
    }

    .endtime {
        font-size: 12px;
        color: #999;
        margin-top: 15px;
    }

    .endtime span {
        color: #333;
    }

    .array-info .buy-btn .can.gray {
        border: 1px solid #eee;
        color: #999;
    }

    .single-line-text{
        width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

</style>
<body>
<%@ include file="/website/common/top.jsp" %>
<%@ include file="/website/common/head.jsp" %>
<%@ include file="/website/common/menu.jsp" %>
<div id="wrap-special">
        <c:if test="${active_ad != null}">
            <div class="special-banner">
                <a href="javascript:showlmurl('');"><img src="<%=getRandomFileserver()%>${active_ad}"></a>
            </div>
        </c:if>


    <div id="flash_sale" class="special-main inner mt-20 clearfix">
        <a href="javascript:void(0);"><img src="${webctx}/images/flashsale.png" alt=""></a>
        <ul class="array-container">

        </ul>
    </div>
    <div id="buy_send" class="special-main inner mt-20 clearfix">
        <a href="javascript:void(0);"><img src="${webctx}/images/buysend.png" alt=""></a>
        <ul class="array-container">

        </ul>
    </div>
    <div id="purchase_gift" class="special-main inner mt-20 clearfix">
        <a href="javascript:void(0);"><img src="${webctx}/images/purchasegift.png" alt=""></a>
        <ul class="array-container">

        </ul>
    </div>

    <div class="line8"></div>
    <div class="line8"></div>
</div>
<%@ include file="/website/common/foot.jsp" %>
<%@ include file="/website/common/sidebar.jsp" %>
<script>
    function setFlashSalesData(fs) {
        if (fs && fs.length > 0) {
            $("#flash_sale").show();
            var itemHtml = "";
            for (var i = 0; i < fs.length; i++) {
                var fsItem = fs[i];
                itemHtml += '<li class="array-item pricture-wrap" pid="' + fsItem.id + '"><div class="array-pic">'
                    + '<a href="/product/info?priceid=' + fsItem.id + '" target="_blank"><img src="' + getRandomFileserver() + fsItem.photo + '" width="200" height="200" onerror="this.src=' + "'/website/images/noimg.jpg'" + '" title="' + fsItem.name + ' ' + fsItem.guige + '">';
                if (fsItem.amount <= 0) {
                    itemHtml += '<span class="sm-mask"></span><span class="sm-mask-center"></span><i>已抢完</i>';
                }
                itemHtml += '</a>'
                    + '<p class="time-text">' + fsItem.description + '</p></div>'
                    + '<div class="array-info"><div class="cost clear">';
                if (fsItem.iscontrol == 0) {
                    if (fsItem.canPromotion == 1) {
                        itemHtml += ("<em>" + ((isuserauth && islogin) ? "<strong>" + "¥" + fsItem.fsPrice + "</strong>" + "<i>￥" + fsItem.price + "</i>" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                    } else {
                        itemHtml += ("<em>" + ((isuserauth && islogin) ? "<strong>" + "¥" + fsItem.price  + "</strong>" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                    }
                } else {
                    itemHtml += ("<em>" + ((isuserauth && islogin) ? "不在本区域销售" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                }
                itemHtml += '</div>'
                    + '<div class="title"><a href="/product/info?priceid=' + fsItem.id + '" target="_blank"><em>' + fsItem.name + '</em>&nbsp;' + fsItem.guige + '</a></div>'
                    + '<div class="text clearfix"><span class="single-line-text fl">' + fsItem.changjia + '</span></div><div class="btn clearfix">'
                    + ' <div class="buy-Num-bd fl"><input type="text" name="amount" onkeyup="inputAmount(this)" class="buy-numInp"';
                if (isuserauth && islogin) {
                    if (fsItem.times !== '') {
                        itemHtml += 'maxnum="' + fsItem.times;
                    } else {
                        itemHtml += 'maxnum="' + fsItem.amount;
                    }
                } else {
                    if (fsItem.time != '') {
                        itemHtml += 'maxnum="' + fsItem.time;
                    } else {
                        itemHtml += 'maxnum="' + fsItem.amount;
                    }
                }
                itemHtml += '" value="1" style="line-height:20px;">'
                    + '<span class="btn-reduce" onclick="lessenamount(this)">-</span>'
                    + ' <span class="btn-add" onclick="addamount(this)">+</span></div>'
                    + ' <span class="fl btn-txt"></span><div class="buy-btn fl">';
                if (islogin && isuserauth && fsItem.iscontrol == 0 && fsItem.price > 0 && (fsItem.times > 0 || fsItem.times === '')) {
                    itemHtml += '<a href="javascript:void(0);" onclick="addtobuy(event,this,' + fsItem.id + ');" class="can"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                } else {
                    itemHtml += '<a href="javascript:void(0);" class="can gray"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                }
                itemHtml += '</div></div>';

                if (fsItem.amount <= 0) {
                    itemHtml += ("<p class='endtime drug-overtime'><em>" + fsItem.soldAmount + "</em> 件单品已抢完啦！</p>");
                } else {
                    if (fsItem.countDown == '1') {
                        itemHtml += ("<p endTime='" + fsItem.surplusSeconds + "' class='endtime drug-overtime'></p>");
                    } else {
                        itemHtml += ("<p class='endtime drug-overtime'>活动火热进行中</p>");
                    }
                }
                itemHtml += ("</div></li>");
            }
            $("#flash_sale .array-container").html(itemHtml);
        } else {
            $("#flash_sale").hide();
        }
    }
    function setBuySendData(bs) {
        if (bs && bs.length > 0) {
            var itemHtml = "";
            for (var i = 0; i < bs.length; i++) {
                var bsItem = bs[i];
                itemHtml += '<li class="array-item pricture-wrap" pid="' + bsItem.id + '"><div class="array-pic">'
                    + '<a href="/product/info?priceid=' + bsItem.id + '" target="_blank"><img src="' + getRandomFileserver() + bsItem.photo + '" width="200" height="200" onerror="this.src=' + "'/website/images/noimg.jpg'" + '" title="' + bsItem.name + ' ' + bsItem.guige + '"></a>'
                    + '<p class="time-text">' + bsItem.description + '</p></div>'
                    + '<div class="array-info"><div class="cost clear">';
                if (bsItem.iscontrol == 0) {
                    itemHtml += ("<em>" + ((isuserauth && islogin) ? "<strong>" + "¥" + bsItem.price + "</strong>" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                    if (bsItem.canPromotion == 1) {
                        itemHtml += '<em>买 ' + bsItem.standardNumber + ' 送 ' + bsItem.sendNumber + ' </em>';
                    }
                } else {
                    itemHtml += ("<em>" + ((isuserauth && islogin) ? "不在本区域销售" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                }
                itemHtml += '</div>'
                    + '<div class="title"><a href="/product/info?priceid=' + bsItem.id + '" target="_blank"><em>' + bsItem.name + '</em>&nbsp;' + bsItem.guige + '</a></div>'
                    + '<div class="text clearfix"><span class="single-line-text fl">' + bsItem.changjia + '</span></div><div class="btn clearfix">'
                    + ' <div class="buy-Num-bd fl"><input type="text" name="amount" onkeyup="inputAmount(this)" class="buy-numInp" maxnum="' + bsItem.amount + '" value="1" style="line-height:20px;">'
                    + '<span class="btn-reduce" onclick="lessenamount(this)">-</span>'
                    + ' <span class="btn-add" onclick="addamount(this)">+</span></div>'
                    + ' <span class="fl btn-txt"></span><div class="buy-btn fl">';
                if (bsItem.iscontrol == 1 || bsItem.price == 0 || bsItem.amount <= 0) {
                    itemHtml += '<a href="javascript:void(0);" class="can gray"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                } else {
                    itemHtml += '<a href="javascript:void(0);" onclick="addtobuy(event,this,' + bsItem.id + ');" class="can"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                }
                itemHtml += '</div></div></div></li>';
            }

            $("#buy_send .array-container").html(itemHtml);
        } else {
            $("#buy_send").css("display", "none");
        }
    }
    function setPurchaseGiftData(pg) {
        if (pg && pg.length > 0) {
            var itemHtml = "";
            for (var i = 0; i < pg.length; i++) {
                var pgItem = pg[i];
                itemHtml += '<li class="array-item pricture-wrap" pid="' + pgItem.id + '"><div class="array-pic">'
                    + '<a href="/product/info?priceid=' + pgItem.id + '" target="_blank"><img src="' + getRandomFileserver() + pgItem.photo + '" width="200" height="200" onerror="this.src=' + "'/website/images/noimg.jpg'" + '" title="' + pgItem.name + ' ' + pgItem.guige + '"></a>'
                    + '<p class="time-text">' + pgItem.description + '</p></div>'
                    + '<div class="array-info"><div class="cost clear">';
                if (pgItem.iscontrol == 0) {
                    itemHtml += ("<em>" + ((isuserauth && islogin) ?  "<strong>" + "¥" + pgItem.price  + "</strong>" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                    if (pgItem.canPromotion == 1) {
                        if (pgItem.minMoney != '') {
                            itemHtml += '<em>满' + pgItem.minMoney + '元送赠品</em>';
                        } else {
                            itemHtml += '<em>买' + pgItem.minNumber +  pgItem.unitname + '送赠品</em>';
                        }
                    }
                } else {
                    itemHtml += ("<em>" + ((isuserauth && islogin) ? "不在本区域销售" : (!islogin ? "登录可见" : "审核通过可见")) + "</em>");
                }

                itemHtml += '</div>'
                    + '<div class="title"><a href="/product/info?priceid=' + pgItem.id + '" target="_blank"><em>' + pgItem.name + '</em>&nbsp;' + pgItem.guige + '</a></div>'
                    + '<div class="text clearfix"><span class="single-line-text fl">' + pgItem.changjia + '</span></div><div class="btn clearfix">'
                    + ' <div class="buy-Num-bd fl"><input type="text" name="amount" onkeyup="inputAmount(this)" class="buy-numInp" maxnum="' + pgItem.amount + '" value="1" style="line-height:20px;">'
                    + '<span class="btn-reduce" onclick="lessenamount(this)">-</span>'
                    + ' <span class="btn-add" onclick="addamount(this)">+</span></div>'
                    + ' <span class="fl btn-txt"></span><div class="buy-btn fl">';
                if (pgItem.iscontrol == 1 || pgItem.price == 0 || pgItem.amount <= 0) {
                    itemHtml += '<a href="javascript:void(0);" class="can gray"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                } else {
                    itemHtml += '<a href="javascript:void(0);" onclick="addtobuy(event,this,' + pgItem.id + ');" class="can"><i class="fa fa-cart-plus"></i>加入购物车</a>';
                }
                itemHtml += '</div></div></div></li>';
            }

            $("#purchase_gift .array-container").html(itemHtml);
        } else {
            $("#purchase_gift").css("display", "none");
        }
    }
    $(function () {
        $w.httpRequest({
            url: "${ctx}/product/promotions",
            ok: function (ret) {
                setFlashSalesData(ret.Data.flash_sale);
                setBuySendData(ret.Data.buy_send);
                setPurchaseGiftData(ret.Data.purchase_gift);

            }
        });

        var flashSaleTimeInterval = window.setInterval(function () {
            var drugOvertimeItems = $(".drug-overtime[endTime]");
            if (drugOvertimeItems.length > 0) {
                drugOvertimeItems.each(function () {
                    var endTime = $(this).attr("endTime");
                    if (endTime > 0) {
                        var h = parseInt(endTime / (60 * 60));//小时
                        var m = parseInt(endTime / 60 % 60);//分钟
                        var s = parseInt(endTime % 60); //秒
                        $(this).html("还剩：<span>" + h + "</span> 时 <span>" + m + "</span> 分 <span>" + s + "</span> 秒");
                        endTime--;
                        $(this).attr("endTime", endTime);
                    } else {
                        $(this).html("活动已截止");
                        $(this).removeAttr("endTime");
                    }
                });
            } else {
                window.clearInterval(flashSaleTimeInterval);
            }
        }, 1000);

    });
    function addamount(obj) {
        var txt = $("[name='amount']", $(obj).parent());
        var n = parseInt(txt.val());
        n++;
        txt.val(n);
        inputAmount(txt);
    }
    function lessenamount(obj) {
        var txt = $("[name='amount']", $(obj).parent());
        var n = parseInt(txt.val());
        n--;
        txt.val(n);
        inputAmount(txt);
    }
    function addtocart(event, obj, pid) {
        var url = ctx + "/order/addToCart?pid=" + pid + "&amount=" + $("[name='amount']", $("[pid='" + pid + "']")).val();
        $w.addCartItem(event, obj, url);
    }
    function addtobuy(event, obj, pid) {
        /*$w.httpRequest({
         url:apiroot+"/order/generateorder2",
         data:{"data":"[{\"priceid\":"+pid+",\"num\":"+$("[name='amount']",$("[pid='"+pid+"']")).val()+"}]"},
         ok:function(ret){
         var ordercode=ret.Data;
         window.location.href=ctx+"/order/orderconfirm?ordercode="+ordercode;
         },fail:function(ret){if(ret.MsgCode=='1001')window.location.href=ctx+"/user/certification";else alert(ret.MsgDesc);return false},all:function(){submiting=false;}
         })*/
        addtocart(event, obj, pid);
    }
    function showlmurl(url) {
        if (url) window.open(url)
    }
</script>
</body>
</html>
